package com.fang.web;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import com.fang.entity.Goods;
import com.fang.service.GoodsService;

public class GoodsServlet extends BaseServlet {
//	分类商品表
	public void category(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		GoodsService service = new GoodsService();
		String json = service.query();
		res.getWriter().write(json);
	}

	public void query(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		Goods goods = new Goods();
		try {
			BeanUtils.populate(goods, req.getParameterMap());
			Integer id=goods.getId();
			System.out.println("id---"+goods.getId());
			GoodsService service = new GoodsService();
			List<Goods> glist = service.querygoods(goods);
			req.setAttribute("glist", glist);
			if(id==null){
				req.getRequestDispatcher("/goods.jsp").forward(req, res);
			}else{
				req.getRequestDispatcher("/goods_detail.jsp").forward(req, res);
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}